import Bullet from "./bullet.js"

class LaserBullet extends Bullet {
    constructor(weapon, start, end, config) {
        super(weapon, start, end, config);
    }

    draw() {
        let ctx = this.game.stage_canvas_ctx;
        let start = this.start_pos;
        let spirit = this.weapon.target_spirit;
        if (!spirit) return;
        let end = spirit.position;

        ctx.strokeStyle = "#ff0000";
        ctx.lineWidth = 5;
        ctx.lineCap = "round";

        ctx.beginPath();
        ctx.setLineDash([10, 10]);
        ctx.moveTo(start[0], start[1]);
        ctx.lineTo(end[0], end[1]);
        ctx.stroke();

        ctx.setLineDash([]);

    };

    check_hit() {
        let ts = new Date().getTime();
        if (this.ts && ts - this.ts < this.config.fire_interval) return;
        this.ts = ts;

        let spirit = this.weapon.target_spirit;
        if (spirit) {
            spirit.blood -= this.power;
            this.weapon.score += this.power;
            this.weapon.fire_duration += this.config.fire_interval;
        }

    };

    is_end() {
        return false;
    };

    move_on() {
    };
}

export default LaserBullet;